import { RobotEntity } from "../RobotEntity";
import { IBehavior } from "./Behavior";
import { EnumBehaviorActionType } from "./EnumBehaviorActionType";
import { SelectorNode } from "./SelectorNode";
import { SequenceNode } from "./SequenceNode";

export class BehaviorTree {

    private _sequence: SequenceNode = new SequenceNode();

    private _selector: SelectorNode = new SelectorNode();

    private _entity: RobotEntity;

    constructor(entity: RobotEntity) {
        this._entity = entity;

    }


    /**
     * 增加行为
     *
     * @param {IBehavior} behavior
     * @memberof BehaviorTree
     */
    public addBehavior(behavior: IBehavior): void {

        if (behavior.actionType === EnumBehaviorActionType.Selector) {
            this._selector.addChild(behavior);
        }
        else if (behavior.actionType === EnumBehaviorActionType.Sequence) {
            this._sequence.addChild(behavior);
        }

    }

    public tick(): void {

        this._selector.execute();
        this._sequence.execute();
    }


}